﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using Microsoft.Practices.WizardFramework;
using PrismFactory.SoftwareFactory.Views.GenerateViewClasses;

namespace PrismFactory.SoftwareFactory.CustomWizardPages.GenerateViewClasses
{
    public partial class GenerateViewClassesPage : CustomWizardPage
    {
        private GenerateViewClassesPageViewModel viewModel;

        public GenerateViewClassesPage()
        {
            InitializeComponent();
        }

        public GenerateViewClassesPage(WizardForm wizard)
            : base(wizard)
        {
            InitializeComponent();
        }

        private void CreateModulePage_Load(object sender, EventArgs e)
        {
            viewModel = new GenerateViewClassesPageViewModel(GetService(typeof (IDictionaryService)) as IDictionaryService);
            viewModel.PropertyChanged += OnViewModelPropertyChanged;
            var view = elementHost1.Child as GenerateViewClassesPageView;
            if (view != null) view.DataContext = viewModel;
            Wizard.OnValidationStateChanged(this);
        }

        private void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            Wizard.OnValidationStateChanged(this);
        }

        public override bool IsDataValid
        {
            get
            {
                if (viewModel != null)
                {
                    return viewModel.IsValid;
                }
                return true;
            }
        }
    }
}